import './public-path.js'
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client'
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom'

// @ts-ignore
export async function bootstrap() {
  console.log('react app bootstraped');
}

// 应用每次进入都会调用
// @ts-ignore
export async function mount(props) {
  console.log('参数传递', props)
  // @ts-ignore
  props.onGlobalStateChange((state, prev) => {
    console.log(state, prev)
  })
  const { container } = props;
  createRoot(container ? container.querySelector('#root') : document.getElementById('root')).render(
    <React.StrictMode>
      <BrowserRouter basename={window.__POWERED_BY_QIANKUN__ ? '/game-brain' : '/'}>
        <App />
      </BrowserRouter>
    </React.StrictMode>
  )
}

// 应用每次卸载都会调用
// @ts-ignore
export async function unmount(props) {
  const { container } = props;
  ReactDOM.unmountComponentAtNode(container ? container.querySelector('#root') : document.querySelector('#root'));
}

// 可选钩子，使用loadMicroApp的方式加载微应用生效
// @ts-ignore
export async function update(props) {
  console.log('update props')
}

// @ts-ignore
if (!window.__POWERED_BY_QIANKUN__) {
  // @ts-ignore
  createRoot(document.getElementById('root')).render(
    <React.StrictMode>
      <BrowserRouter>
        <App />
      </BrowserRouter>
    </React.StrictMode>
  )
}

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
